package com.example.easytts.repository

import com.example.easytts.model.IpUsage
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
interface IpUsageRepository : JpaRepository<IpUsage, Long> {
    @Query("SELECT u FROM IpUsage u WHERE u.ip = :ip AND u.usageDayStr = :usageDayStr")
    fun findByIpAndUsageDay(ip: String, usageDayStr: String): List<IpUsage>

    @Query("SELECT u FROM IpUsage u WHERE u.usageDayStr = :usageDayStr")
    fun findByUsageDayStr(usageDayStr: String): List<IpUsage>

    @Query("SELECT SUM(u.characterCount) FROM IpUsage u WHERE u.ip = :ip")
    fun sumCharacterCountByIp(ip: String): Int?

    @Query("SELECT SUM(u.characterCount) FROM IpUsage u")
    fun sumAllCharacterCount(): Int?
} 